import base64
import cv2
import numpy as np

img = cv2.imread('test_image/Inf_0.jpg')

#1. img(numpy) base64 encode
result, imgencode = cv2.imencode('.jpg', img)
imgbyte = imgencode.tobytes()
# base64编码传输
imgbase64 = base64.b64encode(imgbyte).decode()


#2. base64 decode img(numpy)
newbyte = base64.b64decode(imgbase64)
newarray = np.frombuffer(newbyte, np.uint8)
newimg = cv2.imdecode(newarray, cv2.IMREAD_COLOR)

print(img)